#!/bin/sh
#
# A hook script to verify what is about to be committed.
# Called by git-commit with no arguments.  The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
# 
# Add this file to .git/hooks

# I like something to read during the few seconds of unit testing
echo 'Running unit tests'
fortune 2> /dev/null

# Nicely format all go source files
gofmt -w src/pkg/*/*/*.go

# Run all unit tests
rm test.log -rf
if (make test 2>> test.log >> test.log); then
	echo PASS
	notify-send "Unit tests passed" 2> /dev/null
	exit 0;
else
	cat test.log;
	notify-send "Unit tests failed" 2> /dev/null
	echo
	echo Commit aborted due to failed tests.
	echo 'Fix the code or commit with --no-verify (not on a stable branch!)'
	echo
	exit 2;
fi;

